public class Test {
    class Solution {
        public int longestOnes(int[] nums, int k) {
            int left = 0;
            int right = 0;
            int count = 0;
            int n = nums.length;
            int ret = 0;
            while(right < n) {
                if(nums[right] == 0) {
                    count ++;
                }
                while(count > k) {
                    if(nums[left] == 0) {
                        count --;
                    }
                    left++;
                }
                right++;
                ret = Math.max(ret,right-left);

            }
            return ret;

        }
    }
}
